﻿using System;
using System.Drawing;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents the body of a table.
    /// </summary>
    [Serializable]
    public class TBody : Element {

        private CellHorizontalAlignment? _align;
        private Color? _bgcolor;
        private char? _char;
        private int? _charoff;
        private CellVerticalAlignment? _valign;

        /// <summary>
        /// Determines the horizontal alignment of content inside child cells.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public CellHorizontalAlignment? Align {
            get { return _align; }
            set { _align = value; }
        }

        /// <summary>
        /// Determines the background color of the child cells.
        /// </summary>
        [Obsolete("Non-standard - use CSS instead.")]
        public Color? BGColor {
            get { return _bgcolor; }
            set { _bgcolor = value; }
        }

        /// <summary>
        /// Determines the character to align on.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public char? Char {
            get { return _char; }
            set { _char = value; }
        }

        /// <summary>
        /// Gets the offset number of characters from char to align cell
        /// contents on.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? CharOff {
            get { return _charoff; }
            set {
                if (value == null || value > 0) {
                    _charoff = value;
                } else {
                    throw new ArgumentException(
                        "CharOff must be greater than zero.", "value");
                }
            }
        }

        /// <summary>
        /// Determines the vertical alignment of content inside child cells.
        /// </summary>
        public CellVerticalAlignment? VAlign {
            get { return _valign; }
            set { _valign = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _align, "align", true);
            AttributeWriter.Write(sb, _bgcolor, "bgcolor");
            AttributeWriter.Write(sb, _char, "char");
            AttributeWriter.Write(sb, _charoff, "charoff");
            AttributeWriter.Write(sb, _valign, "valign", true);
        }
    }
}
